package com.simple.piger.component;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.simple.piger.entity.ApplyUser;
import com.simple.piger.entity.InviteCompanyEmp;
import com.simple.piger.service.ApplyUserService;
import com.simple.piger.service.CmsUserService;
import com.simple.piger.service.InviteCompanyEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author baolw
 */
@Component
public class CommonComponent {
    @Autowired
    private CmsUserService cmsUserService;
    @Autowired
    private ApplyUserService applyUserService;
    @Autowired
    private InviteCompanyEmpService inviteCompanyEmpService;

    public String getCompanyIdByCmsUserId(String cmsUserId) {
        EntityWrapper<ApplyUser> applyUserEw = new EntityWrapper<>();
        applyUserEw.eq("cms_sys_user_id", cmsUserId);
        ApplyUser applyUser = applyUserService.selectOne(applyUserEw);

        EntityWrapper<InviteCompanyEmp> empEw = new EntityWrapper<>();
        empEw.eq("apply_user_id", applyUser.getId());
        InviteCompanyEmp emp = inviteCompanyEmpService.selectOne(empEw);

        return emp.getInviteCompanyId();
    }

}
